﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukous.Domain;

namespace Dukous.Security.Domain
{
    /// <summary>
    /// 登录信息
    /// </summary>
    [Serializable]
    public class LogonInfo : Entity<long>
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public LogonInfo()
            : this(System.Guid.NewGuid(), null, "127.0.0.1")
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="account"></param>
        /// <param name="ipAddress"></param>
        public LogonInfo(Guid guid, User user, string ipAddress)
        {
            this.Guid = guid;
            this.User = user;
            this.IpAddress = ipAddress;
            this.LogonTime = DateTime.Now;
            this.RefreshTime = this.LogonTime;
            this.ExpireTime = this.LogonTime.AddYears(1); // 50 年不过期，除非关闭浏览器
            this.IsOff = false;
        }

        /// <summary>
        /// 获取 / 设置 Guid
        /// </summary>
        public virtual Guid Guid { get; set; }

        /// <summary>
        /// 获取 / 设置 用户
        /// </summary>
        public virtual User User { get; set; }

        /// <summary>
        /// 获取 / 设置 登录时间
        /// </summary>
        public virtual DateTime LogonTime { get; set; }

        /// <summary>
        /// 获取 / 设置 登录过期时间
        /// </summary>
        public virtual DateTime ExpireTime { get; set; }

        /// <summary>
        /// 获取 / 设置 刷新时间
        /// </summary>
        public virtual DateTime RefreshTime { get; set; }

        /// <summary>
        /// 获取 / 设置 IP 地址
        /// </summary>
        public virtual string IpAddress { get; set; }

        /// <summary>
        /// 获取 / 设置 是否离线
        /// </summary>
        public virtual bool IsOff { get; set; }
    }
}
